{extend name="common/index"}
{block name="css"}
{/block}

{block name="content"}
<div class="layui-row">
    <form id="editForm" class="layui-form tpl-form-label-long" action="">
        <input type="hidden" name="menu_id" id="menu_id" value="{$data.menu_id|default=''}">
        <div class="layui-field-box">
            <div class="layui-main">
                <div id="selectPid" class="layui-form-item"></div>
                <input type="hidden" name="pid" id="pid" value="{$data.pid|default=0}">

                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color: red;">*&nbsp;</span>菜单名称：</label>
                    <div class="layui-input-block">
                        <input type="text" name="menu_name" value="{$data.menu_name|default=''}" lay-verify="required" placeholder="请输入" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color: red;">*&nbsp;</span>链接地址：</label>
                    <div class="layui-input-block">
                        <input type="text" name="url" value="{$data.url|default=''}" lay-verify="required" placeholder="若无链接，则填 #" class="layui-input">
                        <span style="color: #FFB800;">若是系统链接，请填写模块/控制器/操作，如：admin/Menu/edit； 若是普通链接，则直接填写url地址； 若无链接，则填 # </span>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">链接参数：</label>
                    <div class="layui-input-block">
                        <input type="text" name="params" value="{$data.params|default=''}" class="layui-input">
                        <span style="color: #FFB800;">如：code=article </span>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" >菜单排序：</label>
                    <div class="layui-input-block">
                        <input type="number" name="sort_num" value="{$data.sort_num|default=''}" placeholder="数字越小，越靠前" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">是否显示：</label>
                    <div class="layui-input-block">
                        <input type="radio" name="display" value="1" title="显示在左侧菜单" {eq name="$data.display|default=1" value="1"}checked{/eq}>
                        <input type="radio" name="display" value="2" title="不显示，只做权限验证" {eq name="$data.display|default=1" value="2"}checked{/eq}>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">默认展开：</label>
                    <div class="layui-input-block">
                        <input type="radio" name="is_extend" value="1" title="是" {eq name="$data.is_extend|default=0" value="1"}checked{/eq}>
                        <input type="radio" name="is_extend" value="0" title="否" {eq name="$data.is_extend|default=0" value="0"}checked{/eq}>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">打开方式：</label>
                    <div class="layui-input-block">
                        <input type="radio" name="open_type" value="1" title="当前窗口" {eq name="$data.open_type|default=1" value="1"}checked{/eq}>
                        <input type="radio" name="open_type" value="2" title="新窗口" {eq name="$data.open_type|default=1" value="2"}checked{/eq}>
                    </div>
                </div>
                {eq name="'userInfo.user_id'|session" value="1"}
                <div class="layui-form-item">
                    <label class="layui-form-label">仅admin可见：</label>
                    <div class="layui-input-block">
                        <input type="radio" name="only_admin" value="1" title="是" {eq name="$data.only_admin|default=0" value="1"}checked{/eq}>
                        <input type="radio" name="only_admin" value="0" title="否" {eq name="$data.only_admin|default=0" value="0"}checked{/eq}>
                    </div>
                </div>
                {/eq}
                <div class="layui-form-item">
                    <label class="layui-form-label">用途简介：</label>
                    <div class="layui-input-block">
                        <input type="text" name="description" value="{$data.description|default=''}" placeholder="请输入" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="tpl-form-action">
                <button class="layui-btn layui-btn-radius layui-btn-lg" lay-submit lay-filter="formSubmit">保存</button>
            </div>
        </div>
    </form>
</div>
{/block}

{block name="script"}
<script type="text/javascript">
    layui.use(['form'], function () {
        var form = layui.form;

        //监听提交
        form.on('submit(formSubmit)', function(data){
            var index = layer.load(2, {shade:[0.5,'#000'],time: 10*1000});
            $.post('{:url("save")}', $('#editForm').serialize(), function (result) {
                layer.close(index);
                if (result.code) {
                    layer.msg(result.msg, {shade:[0.5,'#000'],time:1000}, function () {
                        window.location.href = result.url;
                    });
                } else {
                    layer.alert(result.msg, {icon:2, title:'保存失败！'});
                }
            }, 'json');
            return false;
        });
    });

    //上级菜单，级联选择
    layui.config({
        base: '__ADMIN__/js/'
    }).use('linkSelect', function () {
        var linkSelect = layui.linkSelect;
        var inputFrame = $('#selectPid').hasClass("layui-inline") ? 'layui-input-inline' : 'layui-input-block';
        var selectedArr = {$data.pid_multi|default='0'};

        //级联选择，url渲染
        link = linkSelect.render({
            elem: '#selectPid',
            url: "{:url('getMenuLinkSelect')}",
            selectedArr : selectedArr,		//默认选中数组
            inputFrame: inputFrame,          //默认排版方式
            placeholderText : "顶级",	//默认placeholder
            lableName: '上级分类：',
            where: {menu_id:$("#menu_id").val()},
            selected: function (item,dom) {
                var val = link.getValue();
                var val_last = 0;
                if (val[val.length-1] != undefined) {
                    val_last = val[val.length-1].value;
                }
                $("#pid").val(val_last);
            }
        });
    });

</script>
{/block}